clear all
use "datasets/MRA_waste_sites"

*------------------------------------------------------------------------------*
* TABLE A8 : Robustness of results
*------------------------------------------------------------------------------*

* Due to manual WLS-RE, every regression composes of the same repeating steps that involve generating 'new' variables starting from the 'metareg' results. This results in lengthy codelines but is considered necessary for manual WLS-RE. For the same reason, the resulting tables using 'outreg2' have to be manually altered to give the same format as the published tables. The coefficients are, of course, identical.

*------------------------------------------------------------------------------*
* WLS-RE FAT-PET
*------------------------------------------------------------------------------*

quietly metareg elas elas_SE publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_1 = elas_var + tau2
gen elas_SE_1 = sqrt(elas_var_1)
gen precision_sq_1 = 1/elas_var_1
gen precision_1 = sqrt(precision_sq_1)

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'1 = `var'/elas_SE_1
}

reg elas1 precision_1 elas_SE1 publish1 year_publish_c1 site_m1 NPL_n1 NPL_y1 NPL_u1 active_n1 active_u1 job_n1 job_u1 non_haz1 nuclear1 air1 water1 element_u1 North_America1 Asia1 Other_continent1 cleanup01 cleanup21 cleanup31 cleanup_unclear1 dist_greater_mean1 sample_c1 sale_ind1 num_expl_c1 oth_disamen1 oth_amen1 access1 industry1 demoecon1 time_control1 direction1 interaction1 log_log1 OLS_spatial1, nocons cluster(ID_Study)
outreg2 using "tables/Table A8.rtf", replace dec(3) ctitle(WLS-RE FAT-PET)

*------------------------------------------------------------------------------*
*WLS-FE FAT-PET
*------------------------------------------------------------------------------*
foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3  cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'2 = `var'*log_precision
}

reg elas2 elas_SE2 log_precision publish2 year_publish_c2 site_m2 NPL_n2 NPL_y2 NPL_u2 active_n2 active_u2 job_n2 job_u2 non_haz2 nuclear2 air2 water2 element_u2 North_America2 Asia2 Other_continent2 cleanup02 cleanup22 cleanup32 cleanup_unclear2 dist_greater_mean2 sample_c2 sale_ind2 num_expl_c2 oth_disamen2 oth_amen2 access2 industry2 demoecon2 time_control2 direction2 interaction2 log_log2 OLS_spatial2, nocons cluster(ID_Study)
outreg2 using "tables/Table A8.rtf", append ctitle (WLS-FE FAT-PET) dec(3)

*-------------------------------------------------------------------------------
* Without outliers identified in regression diagnostics
*------------------------------------------------------------------------------*
preserve
drop if ID_Uni==176
drop if ID_Uni==177
drop if ID_Uni==647
drop if ID_Uni==648
drop if ID_Uni==649
drop if ID_Uni==842

quietly metareg elas elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3  cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_3= elas_var + tau2
gen elas_SE_3 = sqrt(elas_var_3)
gen precision_3= 1/(elas_SE_3)
gen precision_sq_3= 1/elas_var_3

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'3 = `var'/elas_SE_3
}

reg elas3 precision_3 elas_var3 publish3 year_publish_c3 site_m3 NPL_n3 NPL_y3 NPL_u3 active_n3 active_u3 job_n3 job_u3 non_haz3 nuclear3 air3 water3 element_u3 North_America3 Asia3 Other_continent3 cleanup03 cleanup23 cleanup33 cleanup_unclear3 dist_greater_mean3 sample_c3 sale_ind3 num_expl_c3 oth_disamen3 oth_amen3 access3 industry3 demoecon3 time_control3 direction3 interaction3 log_log3 OLS_spatial3, nocons cluster(ID_Study)
outreg2 using "tables/Table A8.rtf", append dec(3) ctitle(Outlier removed)

restore

*------------------------------------------------------------------------------*
* The effect of outliers: Trimmed dataset (98%)
*------------------------------------------------------------------------------*

preserve 
pctrim elas, percentiles(1 99) recode(miss) replace
recode elas nonmissing=. if elas==.
quietly metareg elas elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_4 = elas_var + tau2
gen elas_SE_4 = sqrt(elas_var_4)
gen precision_sq_4 = 1/elas_var_4
gen precision_4 = sqrt(precision_sq_4)

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'4 = `var'/elas_SE_4
}

reg elas4 precision_4 elas_var4 publish4 year_publish_c4 site_m4 NPL_n4 NPL_y4 NPL_u4 active_n4 active_u4 job_n4 job_u4 non_haz4 nuclear4 air4 water4 element_u4 North_America4 Asia4 Other_continent4 cleanup04 cleanup24 cleanup34 cleanup_unclear4 dist_greater_mean4 sample_c4 sale_ind4 num_expl_c4 oth_disamen4 oth_amen4 access4 industry4 demoecon4 time_control4 direction4 interaction4 log_log4 OLS_spatial4, nocons cluster(ID_Study)
outreg2 using "tables/Table A8.rtf", append dec(3) ctitle(Trimmed 98%)
restore

*------------------------------------------------------------------------------*
*The effect of outliers: Trimmed dataset (95%)
*------------------------------------------------------------------------------*

preserve 
pctrim elas, percentiles(2.5 97.5) recode(miss) replace
recode elas nonmissing=. if elas==.

quietly metareg elas elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_5= elas_var + tau2
gen elas_SE_5 = sqrt(elas_var_5)
gen precision_5= 1/(elas_SE_5)
gen precision_sq_5= 1/elas_var_5

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'5 = `var'/elas_SE_5
}

reg elas5 precision_5 elas_var5 publish5 year_publish_c5 site_m5 NPL_n5 NPL_y5 NPL_u5 active_n5 active_u5 job_n5 job_u5 non_haz5 nuclear5 air5 water5 element_u5 North_America5 Asia5 Other_continent5 cleanup05 cleanup25 cleanup35 cleanup_unclear5 dist_greater_mean5 sample_c5 sale_ind5 num_expl_c5 oth_disamen5 oth_amen5 access5 industry5 demoecon5 time_control5 direction5 interaction5 log_log5 OLS_spatial5, nocons cluster(ID_Study)
outreg2 using "tables/Table A8.rtf", append dec(3) ctitle(Trimmed 95%)

restore

*------------------------------------------------------------------------------*
* The effect of outliers: Trimmed dataset (90%)
*------------------------------------------------------------------------------*

preserve 
pctrim elas, percentiles(5 95) recode(miss) replace
recode elas nonmissing=. if elas==.
quietly metareg elas elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3  cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_6 = elas_var + tau2
gen elas_SE_6 = sqrt(elas_var_6)
gen precision_sq_6 = 1/elas_var_6
gen precision_6 = sqrt(precision_sq_6)

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'6 = `var'/elas_SE_6
}

reg elas6 precision_6 elas_var6 publish6 year_publish_c6 site_m6 NPL_n6 NPL_y6 NPL_u6 active_n6 active_u6 job_n6 job_u6 non_haz6 nuclear6 air6 water6 element_u6 North_America6 Asia6 Other_continent6 cleanup06 cleanup26 cleanup36  cleanup_unclear6 dist_greater_mean6 sample_c6 sale_ind6 num_expl_c6 oth_disamen6 oth_amen6 access6 industry6 demoecon6 time_control6 direction6 interaction6 log_log6 OLS_spatial6, nocons cluster(ID_Study)
outreg2 using "tables/Table A8.rtf", append dec(3) ctitle(Trimmed 90%)
restore
*------------------------------------------------------------------------------*
* Reweighting based on sample reuse
*------------------------------------------------------------------------------*
*'aweight' and 'pweight' give exactly the same results 

quietly metareg elas elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3  cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial, wsse(elas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen elas_var_7= elas_var + tau2
gen elas_SE_7 = sqrt(elas_var_7)
gen precision_7= 1/(elas_SE_7)
gen precision_sq_7= 1/elas_var_7

foreach var in elas elas_SE elas_var publish year_publish_c site_m NPL_n NPL_y NPL_u active_n active_u job_n job_u non_haz nuclear air water element_u North_America Asia Other_continent cleanup0 cleanup2 cleanup3 cleanup_unclear dist_greater_mean sample_c sale_ind num_expl_c oth_disamen oth_amen access industry demoecon time_control direction interaction log_log OLS_spatial{
gen `var'7 = `var'/elas_SE_7
}

reg elas7 precision_7 elas_var7 publish7 year_publish_c7 site_m7 NPL_n7 NPL_y7 NPL_u7 active_n7 active_u7 job_n7 job_u7 non_haz7 nuclear7 air7 water7 element_u7 North_America7 Asia7 Other_continent7 cleanup07 cleanup27 cleanup37  cleanup_unclear7 dist_greater_mean7 sample_c7 sale_ind7 num_expl_c7 oth_disamen7 oth_amen7 access7 industry7 demoecon7 time_control7 direction7 interaction7 log_log7 OLS_spatial7 [aweight=weightsample_reuse], nocons cluster(ID_Study)
outreg2 using "tables/Table A8.rtf", append dec(3) ctitle(Sample reuse weight)

*------------------------------------------------------------------------------*
* Using only the mean observation per study
*------------------------------------------------------------------------------*
*this considerably (and necessarily) reduces the number of moderators that can be used  as most of them have intra-study variance (e.g. the cleanup stages, distance to the waste site). This also justifies using miles_km instead of dist_greater_mean as the metric in which the distance is measured did not change.

*one per study dummy
bys ID_Study: gen one_per_study= 1 if _n == 1 

* using the mean
by ID_Study, sort: egen meanelas = mean(elas)
by ID_Study, sort: egen meanelas_SE = mean(elas_SE)
gen meanelas_var=meanelas_SE*meanelas_SE

quietly metareg meanelas meanelas_SE publish year_publish_c North_America Asia Other_continent miles_km access  if one_per_study==1 , wsse(meanelas_SE) tau2test

scalar tau2 = e(tau2)
display tau2
gen meanelas_var_8 = meanelas_var + tau2
gen meanelas_SE_8 = sqrt(meanelas_var_8)
gen precision_8 = 1/meanelas_SE_8

foreach var in meanelas meanelas_SE publish year_publish_c North_America Asia Other_continent miles_km access{
gen `var'8 = `var'/meanelas_SE_8
}

reg meanelas8 precision_8 meanelas_SE8 publish8 year_publish_c8 North_America8 Asia8 Other_continent8 miles_km8 access8 if one_per_study==1, nocons cluster(ID_Study)
outreg2 using "tables/Table A8.rtf", append dec(3) ctitle(Study means)


clear

